package com.dc.dbus.session.client;

import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicLong;

import com.dc.dbus.transport.commons.ClientSideTransport;

public class DefaultClientStubFatory implements ClientStubFatory {
	
	protected final ClientSideTransport clientSideTansport;
	
	protected final AtomicLong msgIdGen = new AtomicLong(0);
	
	protected final ClientInvokeFeedback clientInvokeFeedback;
	
	public DefaultClientStubFatory(ClientSideTransport clientSideTansport, ClientInvokeFeedback clientInvokeFeedback) {
		super();
		this.clientSideTansport = clientSideTansport;
		this.clientInvokeFeedback = clientInvokeFeedback;
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> T createClientStub(String serviceName, Class<T> interfaceClass, HashMap<String, MethodInfo> methodNameMapInfo) {
		
		return (T) Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[] { interfaceClass },
				new ClientStub(serviceName, msgIdGen, clientSideTansport, clientInvokeFeedback, methodNameMapInfo));
	}
	
}
